#include <stdio.h>

int func1(int j)
{
	int t;
	int v_fp;
	int v_ip;
	int v_sp;
	int v_lr;

	int o_lr;
	int o_sp;
	int o_ip;
	int o_fp;
	int o_pc;

	__asm__ __volatile__
		(
			"mov %0, fp\n\t"
			"mov %1, ip\n\t"
			"mov %2, sp\n\t"
			"mov %3, lr\n\t"
			: "=r"(v_fp),"=r"(v_ip), "=r"(v_sp), "=r"(v_lr)
			:
			: "memory"
		);

	printf("v_fp = 0x%x\nv_ip = 0x%x\nv_sp = 0x%x\nv_lr = 0x%x\n\n",
				v_fp, v_ip, v_sp, v_lr);

	__asm__ __volatile__
		(
			"ldr %3, [fp]\n\t"
			"ldr %0, [fp,#4]\n\t"
			"ldr %1, [fp,#-8]\n\t"
			"ldr %2, [fp,#-12]\n\t"
			: "=r"(o_lr), "=r"(o_sp), "=r"(o_fp), "=r"(o_pc)
			: 
			: "memory"
		);
	
	printf("o_pc = 0x%x\no_lr = 0x%x\no_sp = 0x%x\no_fp = 0x%x\n\n", 
				o_pc, o_lr, o_sp, o_fp);

	t = 100 + j;

	// view registers
	__asm__ __volatile__
	(
		"mov %0, fp\n\t"
		"mov %1, ip\n\t"
		"mov %2, sp\n\t"
		"mov %3, lr\n\t"
		:"=r"(v_fp), "=r"(v_ip), "=r"(v_sp), "=r"(v_lr)
		:
		:"memory"
	);
	printf("v_fp = 0x%x\nv_ip = 0x%x\nv_sp = 0x%x\nv_lr = 0x%x\n\n", 
				v_fp, v_ip, v_sp, v_lr);

	return t;
}

int main()
{
	int i = 0;
	int b;

	b = func1(i);
	printf("b = %d\n", b);

	return 0;
}

